package com.example.iotmanagerment26.service.impl;


import com.example.iotmanagerment26.domain.Device;
import com.example.iotmanagerment26.domain.DeviceLocation;
import com.example.iotmanagerment26.domain.DeviceWithLocation;
import com.example.iotmanagerment26.mapper.DeviceMapper;
import com.example.iotmanagerment26.service.DeviceService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceSeviceImpl implements DeviceService {
    @Resource
    DeviceMapper deviceMapper;

    @Override
    public Device selectDeviceById(int id) {
        return deviceMapper.selectDeviceById(id);
    }

    @Override
    public List<DeviceWithLocation> selectAllDevice() {
        return deviceMapper.selectAllDevice();
    }

    @Override
    public List<DeviceLocation> selectAllDeviceLocation() {
        return deviceMapper.selectAllDeviceLocation();
    }

    @Override
    public int insertDevice(Device device) {
        String name = device.getName();
        Device device1 = deviceMapper.selectDeviceByName(name);
        if (device1!=null){
            return -1;
        }else {
            return deviceMapper.insertDevice(device);
        }
    }

    @Override
    public int deleteDeviceById(int id) {
        return deviceMapper.deleteDeviceById(id);
    }

    @Override
    public int updateInfoById(Device device) {
        return deviceMapper.updateInfoById(device);
    }

    @Override
    public Device selectDeviceByName(String name) {
        return deviceMapper.selectDeviceByName(name);
    }
}
